package com.rchat.pocmini.activity.recharge;

import android.content.Context;

import com.airtalkee.sdk.AirtalkeeAccount;
import com.aso.common.http.delegate.HttpCallbackImpl;
import com.aso.common.http.utils.HttpUtils;
import com.rchat.pocmini.global.HttpCodeGlobal;
import com.rchat.pocmini.global.RequestParam;
import com.rchat.pocmini.global.UrlsGlobal;
import com.rchat.pocmini.util.SharedPreferenceUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description ：
 * @Author itsdf07
 * @Time 2017/9/27
 */

public class ReChargeModelImpl implements RechargeContract.Model {


    @Override
    public void queryPriceList(HttpCallbackImpl callback) {
        //body = {"code":1053,"data":{"platform":1,"version":"1.0","enterprise":1}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1053, null);

        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.QUERY_PRICE_LIST), body, callback);
    }

    @Override
    public void queryRechargeResult(String userName, HttpCallbackImpl callback) {
        Map<String, String> param = new HashMap<>();
        param.put("userName", userName);
        //body = {"code":1052,"data":{"platform":1,"version":"1.0","enterprise":1,"userName":"111110000118"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1052, param);

        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.QUERY_RECHARGE_RESULT), body, callback);
    }

    @Override
    public void noShowRechargeInfoNextTime(Context context, boolean noShowNextTime) {
        SharedPreferenceUtil.saveWithKeyValue(context, "no_show_recharge_info", noShowNextTime);
    }

    @Override
    public boolean isNoShowRechargeInfoNextTime(Context context) {
        return SharedPreferenceUtil.getBooleanValueWithKey(context, "no_show_recharge_info");
    }

    @Override
    public void applyTradeNo(String goodsName, String price, int tradeTypeId, HttpCallbackImpl callback) {

        Map<String, String> param = new HashMap<>();
        param.put("userName", AirtalkeeAccount.getInstance().getUserId());
        param.put("goodsName", goodsName);
        param.put("price", price);
        param.put("tradeTypeId", tradeTypeId + "");
        param.put("tradeType", "App");
        //body = {"code":1051,"data":{"platform":1,"version":"1.0","enterprise":1,"tradeType":"App","goodsName":"购买1年","price":"54.0","userName":"111110000118","tradeTypeId":"2"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1051, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.APPLY_RCHAT_TRADE_NO_URL), body, callback);
    }

}
